package com.cl.code.common.model;

import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author chengliang
 * @since 1.0.0
 */
@Getter
public class UserInfo implements UserDetails {

    private final Long id;
    private final String account;
    private final String nickname;
    private final String password;
    private final Boolean enable;
    private final Collection<? extends GrantedAuthority> authorities;

    public UserInfo(Long id, String account, String nickname, String password, Boolean enable, Collection<? extends GrantedAuthority> authorities) {
        this.id = id;
        this.account = account;
        this.nickname = nickname;
        this.password = password;
        this.enable = enable;
        this.authorities = authorities;
    }

    @Override
    public String getUsername() {
        return this.account;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return enable != null && enable;
    }

}
